<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>VUE Template</title>
    <style>
        .basic{
            width: 400px;
            height: 100px;
            border:1px solid black;
        }
        .happy{
            background-color: red;
            border:2px solid yellowgreen;
        }
        .sad{
            background-color: blue;
            border:2px dotted yellowgreen;
        }
        .normal{
            background-color: gray;
            border:1px dotted yellowgreen;
        }
        .w1{
            font-size: 40px;
        }
        .w2{
            font-weight: 600;
        }
        .w3{
            font-style: italic;
        }
    </style>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <!-- 绑定class样式，字符串写法，适用于：样式的类名不确定，需要动态指定 -->
        <div class="basic" :class='mood' @click="changeMood">{{name}}</div>
        <hr>
        <!-- 绑定class样式，数组写法，适用于：样式的个数不确定，名字不确定 -->
        <div class="basic" :class="classArr">{{name}}</div>
        <hr>
        <!-- 绑定class样式，对象写法，适用于：名字、样式都确定，动态决定用不用 -->
        <div class="basic" :class="classObj">{{name}}</div>
        <hr>
         <!-- 绑定style样式，对象写法 -->
        <div class="basic" :style="styleObj">{{name}}</div>
        <hr>
         <!-- 绑定style样式，数组写法 -->
        <div class="basic" :style="[styleObj,styleObj2]">{{name}}</div>
    </div>
</body>
    <script type="text/javascript">
        
        const vm = new Vue({
            el:'#root',
            data:function(){
                return{
                    name:'trentwu',
                    mood:'normal',
                    classArr:['w1','w2','w3'],
                    classObj:{
                        w1:false,
                        w2:false
                    },
                    styleObj:{
                        fontSize:'40px',
                        color:'blue',
                    },
                    styleObj2:{
                        backgroundColor:'yellow'
                    }
                }
            },
            methods:{
                changeMood(e){
                    const arr=['happy','sad','normal'];
                    let randomNumber = Math.floor(Math.random()*3);
                    this.mood=arr[randomNumber];
              }
          }

        })
    </script>
</html>